package com.canis.stockmanager.web;

import com.canis.stockmanager.comm.aop.LoggerManage;
import com.canis.stockmanager.domai.SysUser;
import com.canis.stockmanager.domai.VpnBox;
import com.canis.stockmanager.domai.result.ExceptionMsg;
import com.canis.stockmanager.domai.result.ResponseData;
import com.canis.stockmanager.domai.view.VpnBoxView;
import com.canis.stockmanager.utils.util;
import com.fasterxml.jackson.databind.util.JSONPObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.function.Function;
import com.canis.stockmanager.repository.VpnBoxRepository;
@Controller
@RequestMapping("/online")
public class OnlineController extends BaseController {
    @Autowired
    private VpnBoxRepository vpnBoxRepository;
    @RequestMapping(value = "/query", method = RequestMethod.GET)
    @ResponseBody
    public ResponseData query(Model model,@RequestParam(value = "start", defaultValue = "0") Integer start,@RequestParam(value = "sort", defaultValue = "") String sortStr,
                              @RequestParam(value = "limit", defaultValue = "10") Integer limit,VpnBox vpn_box, HttpServletResponse response) {
        Pageable pageable = util.getPageable(sortStr,start,limit);
        Page<VpnBox> pages=vpnBoxRepository.findByMacContainingAndResourceIpContaining(vpn_box.getMac(),vpn_box.getResourceIp() ,pageable);
        List<VpnBox> vbs=pages.getContent();
        return new ResponseData(ExceptionMsg.SUCCESS, "",pages.getTotalElements(),vbs);
    }
    @RequestMapping(value="/",method=RequestMethod.GET)
    public String online(Model model) {

        return "online";
    }

}
